package com.sjksy.demo.mapper;

import com.sjksy.demo.domain.Employee;
import com.sjksy.demo.domain.Guide;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sjksy.demo.dto.guide.GuideDto;
import com.sjksy.demo.vo.employee.EmployeeResponseVo;
import com.sjksy.demo.dto.guide.GuideInfoDto;
import com.sjksy.demo.dto.guide.GuideInfoDto;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
* @author guyueyuan
* @description 针对表【guide】的数据库操作Mapper
* @createDate 2024-12-11 15:37:02
* @Entity com.sjksy.demo.domain.Guide
*/
@Repository
@Mapper
public interface GuideMapper extends BaseMapper<Guide> {
    /**
     * 根据员工id删除导游
     * @param id
     */
    @Delete("delete from guide where employee_id=#{id}")
    void delete(Integer id);

    /**
     * 获取导游号和导游等级
     * @param employeeId
     * @return
     */
    @Select("select guide_number,guide_level from guide where employee_id=#{employeeId}")
    GuideDto getNumAndLev(Integer employeeId);

    /**
     * 根据导游id获取其所属分公司的id
     * @param guideId 导游id
     * @return Integer 查询出来的分公司id
     */
    @Select("select em.branch_id\n" +
            "from guide as gu\n" +
            "LEFT JOIN employee as em\n" +
            "on em.employee_id=gu.employee_id\n" +
            "where gu.guide_id=#{guideId}")
    Integer getBranchIdByGuideId(Integer guideId);

    /**
     * 根据导游id获取所属分公司名称
     * @param guideId
     * @return
     */
    @Select("select b.branch_id from guide g,employee e,branch b " +
            "where guide_id=#{guideId} and e.employee_id=g.employee_id" +
            " and e.branch_id=b.branch_id")
    Integer getBranchName(Integer guideId);



    /**
     * 根据导游id查询导游信息(员工信息)
     * @param guideId 导游id
     * @return  查询出来的分公司id
     */

    @Select("select guide_number,guide_level,em.employee_id,br.branch_id,name,id_card_number,branch_name\n" +
            "from guide as gu\n" +
            "LEFT JOIN employee as em\n" +
            "on em.employee_id=gu.employee_id\n" +
            "Left Join branch as br\n" +
            "on br.branch_id=em.branch_id\n"+
            "where gu.guide_id=#{guideId}")
    GuideInfoDto getEmployeeInfoByGuideId(Integer guideId);


}